package com.lastproject.ejb.mdbs;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

import com.lastproject.ejb.service.MailSender;

/**
 * Message-Driven Bean implementation class for: FirstMDB
 */
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") }, mappedName = "jms/firstResource")
public class ForLibraryMDB implements MessageListener {

	public ForLibraryMDB() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see MessageListener#onMessage(Message)
	 */
	public void onMessage(Message message) {

		String bookName = null;
		String userEmail = null;
		try {
			bookName = message.getStringProperty("bookName");
			userEmail = message.getStringProperty("userEmail");
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		MailSender mail = new MailSender();
		try {

			mail.sendReminderFromLibrarian(userEmail, bookName);

		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}

}
